<%#
# To change this template, choose Tools | Templates
# and open the template in the editor.
%>

<% title "General Settings", false %>

<div id="page-header">
  
  <div class="page-help-section">
    
  </div>
  <div class="page-help-navigator">
    <span id="help-button">Help</span>
  </div>
  
  <span class="page-icons page_config_icon"></span>
  <h1 class="page-name">General Settings</h1>
</div>

<br/>

<div class="page-form">
  <% form_for @general, :url => {:controller => "admin/settings/general", :action => 'update'} , :method => :put do |f| %>
    <div class="form_row">
      <%= f.label :org_name, "Organization Name" %>
      <%= f.text_field :org_name %>
    </div>
  
    <div class="form_row">
      <%= f.label :org_tagline, "Tagline" %>
      <%= f.text_field :org_tagline %>
    </div>
  
    <div class="form_row">
      <%= f.label :org_address, "Address" %>
      <%= f.text_field :org_address %>
    </div>
  
    <div class="form_row">
      <%= f.label :org_city, "City" %>
      <%= f.text_field :org_city %>
    </div>
  
    <div class="form_row">
      <%= f.label :org_state, "State" %>
      <%= f.text_field :org_state %>
    </div>
  
    <div class="form_row">
      <%= f.label :org_pincode, "Pincode" %>
      <%= f.text_field :org_pincode %>
    </div>
  
    <div class="form_row">
      <%= f.label :org_country, "Country" %>
      <%= f.select :org_country, Country.all.collect {|c| [c.name, c.id]} %>
    </div>
  
    <div class="form_row">
      <%= f.label :org_timezone, "Timezone" %>
      <%= f.select :org_timezone, Timezone.all.collect {|t| [t.name, t.id]} %>
    </div>
  
    <div class="form_row">
      <% time = Time.now %>
      <%= f.label :org_dateformat, "Date Format" %>
      <ul>
        <li><%= f.radio_button :org_dateformat, 0, :checked => @general.checked_dateformat?(0) %> <span><%= time.strftime("%B %d, %Y") %></span></li>
        <li><%= f.radio_button :org_dateformat, 1, :checked => @general.checked_dateformat?(1) %> <span><%= time.strftime("%Y/%m/%d") %></span></li>
        <li><%= f.radio_button :org_dateformat, 2, :checked => @general.checked_dateformat?(2) %> <span><%= time.strftime("%m/%d/%Y") %></span></li>
        <li><%= f.radio_button :org_dateformat, 3, :checked => @general.checked_dateformat?(3) %> <span><%= time.strftime("%d/%m/%Y") %></span></li>
      </ul>
    </div>
  
    <div class="form_row">
      <%= f.label :org_timeformat, "Time Format" %>
      <ul>
        <li><%= f.radio_button :org_timeformat, 0 , :checked => @general.checked_timeformat?(0) %> <span><%= time.strftime("%I:%M %p").downcase  %></span></li>
        <li><%= f.radio_button :org_timeformat, 1 , :checked => @general.checked_timeformat?(1)  %> <span><%= time.strftime("%I:%M %p")%></span></li>
        <li><%= f.radio_button :org_timeformat, 2 , :checked => @general.checked_timeformat?(2)  %> <span><%= time.strftime("%H:%M %p") %></span></li>
      </ul>
    </div>
  
    <div class="form_row">
      <%= f.label :org_calendar, "Calendar Days" %>
      <%= f.text_field :org_calendar, :hidden => true %>
      <ul class="inline">
	<li><%= check_box_tag 'days[0]', 'Y' , false, :onchange => 'setCalendarDays(0)' %> <span>Monday</span></li>
	<li><%= check_box_tag 'days[1]', 'Y' , false, :onchange => 'setCalendarDays(1)' %> <span>Tuesday</span></li>
	<li><%= check_box_tag 'days[2]', 'Y' , false, :onchange => 'setCalendarDays(2)'  %> <span>Wednesday</span></li>
	<li><%= check_box_tag 'days[3]', 'Y' , false, :onchange => 'setCalendarDays(3)'  %> <span>Thursday</span></li>
	<li><%= check_box_tag 'days[4]', 'Y' , false, :onchange => 'setCalendarDays(4)'   %> <span>Friday</span></li>
	<li><%= check_box_tag 'days[5]', 'Y' , false, :onchange => 'setCalendarDays(5)'  %> <span>Saturday</span></li>
	<li><%= check_box_tag 'days[6]', 'Y' , false, :onchange => 'setCalendarDays(6)'   %> <span>Sunday</span></li>
      </ul>
      <script type="text/javascript">
        if($('#general_setting_org_calendar').val().length == 0){
          $('#general_setting_org_calendar').val("NNNNNNN");
        }
        var calVal = $('#general_setting_org_calendar').val();
        for(var i=0 ; i<7 ; i++){
          if(calVal.charAt(i) == 'Y'){
            $("#days_"+i).attr('checked', true);
            //alert(i);
          } else {
            $("#days_"+i).attr('checked', false);
          }
        }
      </script>
      <script type="text/javascript">
        function setCalendarDays(index){
          var calendar = $('#general_setting_org_calendar');
          var chkBox = $("#days_" + index );
          var curVal = $(calendar).val();
          if(chkBox.is(':checked')){
            curVal = curVal.substring(0,index) + 'Y' + curVal.substring(index+1); 
          } else {
            curVal = curVal.substring(0,index) + 'N' + curVal.substring(index+1); 
          }
          $(calendar).val(curVal);
        }
      </script>
    </div>
  
    <div class="form-row">
      <br/>
      <%= f.submit "Save changes" , :class => 'submit_button' %>
    </div>
  
  <% end %>
</div>